package com.boe.hbd.client.activity;

import com.boe.hbd.client.service.ConfigurationService;
import com.boe.hbd.client.service.LocationService;
import com.boe.hbd.client.service.ServiceManager;
import com.boe.hbd.client.service.support.FileBasedConfigurationService;

import android.test.ActivityInstrumentationTestCase2;
public class BeautyOfEarthWidgetTest extends ActivityInstrumentationTestCase2 {

	public BeautyOfEarthWidgetTest() {
		super("com.boe.hbd.client", BeautyOfEarthActivity.class);
	}

	public void test_configuration() throws Throwable {
		ServiceManager.getInstance(getActivity().getBaseContext());
		ConfigurationService service = ServiceManager.getInstance(null).getService(ConfigurationService.class);
		service.save("AAA", "AA");
		service.save("BB", 100L);
		service.destroy(getActivity().getBaseContext());

		service.save("AAA", "");
		service.save("BB" , "" );
		assertEquals(service.get("AAA", ""), "" );
		assertEquals(service.get("BB" , ""), "" );
		
		service.initialize(getActivity().getBaseContext());
		assertEquals(service.get("AAA", ""), "AA");
		assertEquals(service.get("BB", 10L), new Long(100L));
		((FileBasedConfigurationService) service).delete(getActivity().getBaseContext());
	}
	
	public void test_location_service() throws Throwable {
		LocationService lservice = ServiceManager.getInstance(null).getService(LocationService.class);
		assertNotNull(lservice.getLocation());
	}
	// public void testActivity() {
	// BeautyOfEarthActivity activity = getActivity();
	// assertNotNull(activity);
	// }
	//
	// public void test_actitity_create() throws Throwable {
	// EntityManager manager =
	// EntityManagerFactory.getInstance().getManager(getActivity().getBaseContext(),
	// "landscape");
	// List<Landscape> all = manager.query(Landscape.class, "activitiesAll",
	// null);
	// for (Landscape act : all) {
	// assertEquals(manager.remove(act), 1);
	// }
	//
	// for (int i = 0; i < 3; i++) {
	// Landscape act = new Landscape();
	// act.setName("namedEntities");
	// manager.create(act);
	// }
	// List<Landscape> queriedEntities = manager.query(Landscape.class,
	// "activitiesByName",
	// new ChainedMap<String, Object>().chainedPut("name", "namedEntities"));
	// assertEquals(queriedEntities.size(), 3);
	//
	// for (Landscape act : queriedEntities) {
	// act.setDescription("updated");
	// manager.update(act);
	// }
	// List<Landscape> updatedEntities = manager.query(Landscape.class,
	// "activitiesByName",
	// new ChainedMap<String, Object>().chainedPut("name", "namedEntities"));
	// assertEquals(updatedEntities.size(), 3);
	// for (Landscape act : updatedEntities) {
	// assertEquals( act.getDescription() , "updated" ) ;
	// }
	//
	// }
}
